local fk__weilun = fk.CreateSkill {

  name = "fk__weilun",

  tags = { Skill.Compulsory, },

}

local U = require "packages/utility/utility"


fk__weilun:addEffect(fk.AfterCardsMove, {

  anim_type = "control",

  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(fk__weilun.name) then
      for _, move in ipairs(data) do
        if move.toArea ~= Card.Void then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerSpecial then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = player:usedSkillTimes(fk__weilun.name, Player.HistoryTurn)
    room:setPlayerMark(player, "@fk__weilun-turn", x)
    local skills = Fk.generals[player.general]:getSkillNameList(true)
    if player.deputyGeneral ~= "" then
      table.insertTable(skills, Fk.generals[player.deputyGeneral]:getSkillNameList(true))
    end
    local skill = skills[x]
    if skill then
      room:addTableMark(player, "fk__weilun_skill-turn", skill)
    end
    player:drawCards(1, fk__weilun.name)
  end,
})

fk__weilun:addEffect("invalidity", {
  name = "#fk__weilun_invalidity",
  invalidity_func = function(self, player, skill)
    return table.contains(player:getTableMark("fk__weilun_skill-turn"), skill.name)
  end
})

return fk__weilun